package _53MaximumSubarray;

public class CSolution {

    public static void main(String[] args) {
        System.out.println("aa");
//        System.out.println(maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
        System.out.println(maxSubArray(new int[]{-2, 1}));
    }

    private static int maxSubArray(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            int result = nums[i];
            max = Math.max(max, result);
            for (int j = i + 1; j < nums.length; j++) {
                result = result + nums[j];
                max = Math.max(max, result);
            }
        }
        return max;
    }
    //TODO better?
}
